package model

import "gorm.io/gorm"

type FavoritePicture struct {
	Model
	FavoriteID uint `json:"favorite_id,omitempty"`
	PictureID  uint `json:"picture_id,omitempty"`
}

func (fp FavoritePicture) TableName() string {
	return "img_favorite_picture"
}

func (fp FavoritePicture) Create(db *gorm.DB) error {
	return db.Create(&fp).Error
}

func (fp FavoritePicture) Update(db *gorm.DB) error {
	return db.Model(&fp).Updates(&fp).Error
}

func (fp FavoritePicture) Get(db *gorm.DB) (*FavoritePicture, error) {
	var favPic FavoritePicture
	err := db.Where(&fp).First(&favPic).Error
	return &favPic, err
}

func (fp FavoritePicture) List(db *gorm.DB, pageOffset int, pageSize int) ([]*FavoritePicture, error) {
	var favPics []*FavoritePicture
	err := db.Where(&fp).Offset(pageOffset).Limit(pageSize).Find(&favPics).Error
	return favPics, err
}

func (fp FavoritePicture) Delete(db *gorm.DB) error {
	return db.Delete(&fp).Error
}

func (fp FavoritePicture) Count(db *gorm.DB) (int, error) {
	var count int64
	err := db.Model(&fp).Where(&fp).Count(&count).Error
	return int(count), err
}
